package com.symone.webcms.model;

import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.IdType;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.symone.webcms.model.base.TreeNode;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 *   @description : Menu 实体类
 *   ---------------------------------
 * 	 @author Archer Chu
 *   @since 2019-01-02
 */
@Data
@Accessors(chain = true)
@TableName("sys_menu_table")
public class Menu extends Model<Menu> implements Comparable<Menu>,TreeNode<Menu> {

    private static final long serialVersionUID = 1L;

    /**
     * ID
     */
	@ApiModelProperty("ID")
	@TableId(value="id", type= IdType.AUTO)
	private Long id;
    /**
     * 上级菜单ID
     */
	@ApiModelProperty("上级菜单ID")
	private Long pid;
    /**
     * 菜单名称
     */
	@ApiModelProperty("菜单名称")
	private String name;
    /**
     * 菜单代码
     */
	@ApiModelProperty("菜单代码")
	private String code;
    /**
     * 菜单深度
     */
	@ApiModelProperty("菜单深度")
	private Integer deep;
    /**
     * shiro代码
     */
	@ApiModelProperty("shiro代码")
	@TableField("shiro_code")
	private String shiroCode;
    /**
     * 路径
     */
	@ApiModelProperty("路径")
	private String url;
    /**
     * 图标
     */
	@ApiModelProperty("图标")
	private String icon;
    /**
     * 排序
     */
	@ApiModelProperty("排序")
	private Integer sorting;
	/**
	 * 快捷方式
	 */
	@ApiModelProperty("快捷方式")
	@TableField("short_cut")
	private Integer shortCut;

	/**
	 * 快捷方式
	 */
	@ApiModelProperty("是否显示")
	private Integer display;

	/**
     * 是否删除
     */
	@ApiModelProperty("是否删除")
	private Integer deleted;
	@TableField("create_time")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	private Date createTime;
	@TableField("update_time")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	private Date updateTime;

	@TableField(exist = false)
	private List<Menu> children;

	@TableField(exist = false)
	private List<MenuAction> actions;

	@Override
	protected Serializable pkVal() {
		return this.id;
	}

	@Override
	public int compareTo(Menu m) {
		return this.sorting - m.sorting;
	}

	@Override
	public List<Menu> getChildren() {
		return this.children;
	}

	@Override
	public void setChildren(List<Menu> children) {
		this.children = children;
	}
}
